#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author: zhangZW
@file: database.py
@time: 2022/09/09
@des: 数据库链接,目前仅支持mysql
"""
from config import RunConfig
import pymysql


class MySql:
    def __init__(self):
        self.mysql = pymysql.connect(**RunConfig.MySQL)
        self.cursor = self.mysql.cursor()

    def execute(self, _sql):
        self.cursor.execute(_sql)

    def getone(self):
        return self.cursor.fetchone()

    def getall(self) -> tuple:
        return self.cursor.fetchall()

    def close(self):
        self.mysql.close()

    def commit(self):
        self.mysql.commit()

    def conn_commit(self):
        self.cursor.connection.commit()


if __name__ == '__main__':
    my = MySql()
    sql = 'select version()'
    my.execute(sql)
    print(my.getone(), type(my.getone()))

